import { createApp, App } from "vue";

import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import zhCn from "element-plus/es/locale/lang/zh-cn";

import App from "@/App.vue";
import store from "./store";
import router from "./router";

import registerGlobalComponent from "@/utils/registerGlobalComponent";

import "normalize.css";
import "./styles/global.scss";

let app: App;
const render = (props: any) => {
  const { container } = props;

  app = createApp(App);

  // 全局注册组件
  registerGlobalComponent(app);

  app.use(store);
  app.use(router);
  app.use(ElementPlus, {
    locale: zhCn, // 中文语言包：能让所有element-plus组件变成中文
  });

  // 添加全局变量 $vue -> 目的将来其他地方可以使用 app
  window.$vue = app;

  app.mount(container ? container.querySelector("#app") : "#app");
};

import {
  renderWithQiankun,
  qiankunWindow,
} from "vite-plugin-qiankun/dist/helper";

renderWithQiankun({
  mount(props) {
    render(props);
  },
  bootstrap() {},
  unmount(props: any) {
    app.unmount();
    app = null;
  },
});

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render({});
}
